package com.hefei.common.utils;

import lombok.Data;

/**
 * @author caizhengjun
 * @date 2021/3/4 下午5:13
 */
@Data
public class R {

    private String message;

    private Integer code;

    private Boolean success;

    private Object data;

    private R() {
    }

    public static R ok() {
        R r = new R();
        r.setCode(ResultCode.SUCCESS);
        r.setSuccess(true);
        r.setMessage("请求成功！");
        return r;
    }

    public static R fail() {
        R r = new R();
        r.setCode(ResultCode.ERROR);
        r.setSuccess(false);
        r.setMessage("请求失败！");
        return r;
    }

    public R data(Object data) {
        this.setData(data);
        return this;
    }

    public R code(Integer code) {
        this.setCode(code);
        return this;
    }

    public R message(String message) {
        this.setMessage(message);
        return this;
    }
}
